const DB = wx.cloud.database().collection('mission_list');
const util = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title: "添加任务",
    isTransform: false,
    isBack: true,
    show: false,
    time: '',
    date: '',
  },
  formSubmit: function (e) {
    wx.requestSubscribeMessage({
      tmplIds: ['em9B7aike40C2AK0LWNHyEybYI8VjdZa4UIcrzdAo-4'],
      success (res) {
        console.log(res);
       },
       fail: function(err){
         console.log(err);
       }
    })
    let user = {
      state: false
    };
    let all = util.extend(user, e.detail.value);
    console.log(all);
    if (e.detail.value.mission == "") {
      wx.showToast({
        title: '请输入标题',
        icon: 'none'
      })
    } else if (e.detail.value.context == "") {
      wx.showToast({
        title: '请输入详细内容',
        icon: 'none'
      })
    } else {
      DB.add({
        data: all,
        success: res => {
          console.log("添加成功", res);
          wx.showToast({
            title: '添加成功',
          })
          wx.navigateBack({
            delta: 1,
          })
        },
        fail: res => {
          console.log("添加失败", res);
        }
      })
    }
  },
  formReset: function () {},
  TimeChange(e) {
    this.setData({
      time: e.detail.value
    })
  },
  DateChange(e) {
    this.setData({
      date: e.detail.value
    })
  },
  onLoad: function () {
    let that = this
    let data = util.formatDate(new Date())[0];
    let time = util.formatDate(new Date())[1];
    that.setData({
      date: data,
      time: time,
    })
  }
})